package edu.stthomas.edu.seis770.simpleclock;

/**
 * A factory class to provide a singleton clock states
 */
class ClockStateFactory {
    private static DisplayTime displayTime = null;
    private static SetHours setHours = null;
    private static SetMinutes setMinutes = null;
    private static SetSeconds setSeconds = null;


    public static ClockState getClockState(Class<? extends ClockState> clockStateClass, ClockModel clockModel) {
        ClockState clockState = null;
        if (clockStateClass.isAssignableFrom(DisplayTime.class)) {
            if (displayTime == null) {
                displayTime = new DisplayTime(clockModel);
            }
            clockState = displayTime;
        } else if (clockStateClass.isAssignableFrom(SetHours.class)) {
            if (setHours == null) {
                setHours = new SetHours(clockModel);
            }
            clockState = setHours;
        } else if (clockStateClass.isAssignableFrom(SetMinutes.class)) {
            if (setMinutes == null) {
                setMinutes = new SetMinutes(clockModel);
            }
            clockState = setMinutes;
        } else if (clockStateClass.isAssignableFrom(SetSeconds.class)) {
            if (setSeconds == null) {
                setSeconds = new SetSeconds(clockModel);
            }
            clockState = setSeconds;
        }

        return clockState;
    }
}
